import { getGoodList } from '../apis/good'
import { addGoodList } from '../apis/good'
import { getGoodTypeList } from '../apis/good'
import { getServeiceTypeList } from '../apis/good'
import qs from 'querystring'
export default {
    state: {
        GoodList: [],
        TypeList:[],
        ServiceTypeList:[]
    },
    effects: {
        *getGoodBySaga({ payload }, { put, call }) {
            const res = yield call(getGoodList, qs.stringify(payload))
            // console.log("search",res);
            yield put({ type: "initGoodList", payload: res.rows })
        },
        // 新增：
        *addGoodBySaga({ payload }, { put, call }) {
            const res = yield call(addGoodList,  qs.stringify(payload))
            // console.log("GoodModel新增",res);
            yield put({ type: "addGoodList", payload: res })
        },
        // 获取商品分类：
        *getGoodTypeBySaga({ payload }, { put, call }) {
            const res = yield call(getGoodTypeList,qs.stringify(payload))
            console.log("商品类型",res);
            yield put({ type: "getGoodTypeList", payload: res.rows.children })
        },
        // 获取服务分类：
        *getServiceTypeBySaga({ payload }, { put, call }) {
            const res = yield call(getServeiceTypeList,qs.stringify(payload))
            // console.log("服务类型",res);
            yield put({ type: "getServeiceTypeList", payload: res.rows.children })
        },
    },
    reducers: {
        initGoodList(state, action) {
            state.GoodList = action.payload
            // return{
            //     ...state,
            //     GoodList:action.payload
            // }
        },
        addGoodList(state, action) {
            state.GoodList = action.payload
        },
        getGoodTypeList(state, action) {
            state.TypeList = action.payload
        },
        getServeiceTypeList(state, action) {
            state.ServiceTypeList = action.payload
        }
    }
}